﻿
#ifndef PICTURETCPSERVER_H
#define PICTURETCPSERVER_H

#include <QWidget>
#include <QtNetwork>
#include <QTcpSocket>
#pragma execution_character_set("utf-8")
QT_BEGIN_NAMESPACE
namespace Ui { class PictureTcpServer; }
QT_END_NAMESPACE

class PictureTcpServer : public QWidget

{
    Q_OBJECT

public:
    PictureTcpServer(QWidget *parent = nullptr);
    ~PictureTcpServer();


    void SaveImage(QByteArray ba);  //保存图片
    void SaveData(QByteArray ba);   //保存数据

    void DelayTime(int ms);
    void ChangeEnable(bool isEnable);
    void StartListen();             //开始监听

private slots:
    void on_btnStart_clicked();

    void on_btnClear_clicked();

    void on_btnSend_clicked();

    void AcceptConnection();        //建立连接
    void ReadMyData();              //接收数据带检验
    void ReceiveData();             //普通方式接收数据
    void DisplayError(QAbstractSocket::SocketError socketError);

    void on_rbtnPT_toggled(bool checked);

private:
    Ui::PictureTcpServer *ui;

    QTcpServer m_tcpServer;
    QTcpSocket *m_pTcpServerConnection;

    QStringList m_fileNames;
    int m_count;                    //统计存放图片的张数

    QByteArray m_message;           //存放从服务器接收到的字符串
    quint16 m_basize;               //存放文件大小信息
};

#endif // PICTURETCPSERVER_H
